package com.snj.visangedu;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.VideoView;

import com.snj.visangedu.lib.CustomHttpClient;
import com.snj.visangedu.lib.Global;
import com.snj.visangedu.news.NewsAdapter2;
import com.snj.visangedu.news.NewsItem2;

public class ConsultFragment extends Fragment implements OnClickListener {
	private final String TAG = "Menu1_2Fragment";
	
	ImageView img_teacher0 = null;
	ImageView img_teacher1 = null;
	ImageView img_teacher2 = null;
	
	ScrollView scrv_menu2 = null;
	
	RelativeLayout rlly_menu2_content = null;
	
	//VideoView menu2_videoview = null;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View root = inflater.inflate(R.layout.fragment_consult,
				container, false);
		return root;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		Log.d(TAG, "onActivityCreated");
		
		super.onActivityCreated(savedInstanceState);
		init_widget();
	}
	
	private void init_widget() {
		View view = getView();
		
		img_teacher0 = (ImageView)view.findViewById(R.id.img_menu2_teacher0);
		img_teacher1 = (ImageView)view.findViewById(R.id.img_menu2_teacher1);
		img_teacher2 = (ImageView)view.findViewById(R.id.img_menu2_teacher2);
		scrv_menu2 = (ScrollView)view.findViewById(R.id.menu2_scrv);
		
		rlly_menu2_content = (RelativeLayout)view.findViewById(R.id.rlly_menu2_content);
		
		/*
		menu2_videoview = (VideoView)view.findViewById(R.id.menu2_videoview);
		menu2_videoview.setOnCompletionListener(new OnCompletionListener() {
			
			@Override
			public void onCompletion(MediaPlayer mp) {
				// TODO Auto-generated method stub
				menu2_videoview.start();
			}
		});
		
		MediaController mediaController = new MediaController(getActivity());
		
		mediaController.setAnchorView(menu2_videoview);
		
		
		Uri video = Uri.parse("http://viewnpop.com/snj/visangedu/StudyViewLogo.mp4");
		
		menu2_videoview.setMediaController(mediaController);
		
		menu2_videoview.setVideoURI(video);
		menu2_videoview.setOnPreparedListener(PreparedListener);
		
		//menu2_videoview.requestFocus();
		
		menu2_videoview.start();
		*/
		img_teacher0.requestFocus();
		scrv_menu2.smoothScrollTo(0, 0);
	}
	
	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onClick(View v) {
		
		switch(v.getId())
		{
		case R.id.img_menu2_submenu1:
			break;
		case R.id.img_menu2_submenu2:
			break;
		}
	}
	
	/*
	private OnVideoSizeChangedListener onVideoSizeChangedListener =  
			new OnVideoSizeChangedListener() {  
			 public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {  
			  LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,  
			ViewGroup.LayoutParams.FILL_PARENT);  
			  menu2_videoview.setLayoutParams(lp);  
			 }  
			};
	
	MediaPlayer.OnPreparedListener PreparedListener = new OnPreparedListener() {
		
		@Override
		public void onPrepared(MediaPlayer m) {
			// TODO Auto-generated method stub
			
			try {
                if (m.isPlaying()) {
                    m.stop();
                    m.release();
                    m = new MediaPlayer();
                }
                
                m.setOnVideoSizeChangedListener(onVideoSizeChangedListener);  
                
                LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,  
              ViewGroup.LayoutParams.FILL_PARENT);  
                menu2_videoview.setLayoutParams(lp);
                menu2_videoview.setMediaController(null);
                
                m.setVolume(0f, 0f);
                m.setLooping(false);
                m.start();
            } catch (Exception e) {
                e.printStackTrace();
            }   
		}
	};*/
}
